package icu.nil.demo.shell.config

import icu.nil.demo.shell.interceptor.ShellWebSocketInterceptor
import icu.nil.demo.shell.websocket.WebSSHWebSocketHandler
import org.springframework.context.annotation.Configuration
import org.springframework.web.socket.config.annotation.EnableWebSocket
import org.springframework.web.socket.config.annotation.WebSocketConfigurer
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry

/**
 * Create by xiangliyou on 2020/3/10 16:24.
 * email: xiangliyou@aliyun.com
 * Des: websocket配置
 */
@Configuration
@EnableWebSocket
class WebSSHWebSocketConfig(
        private val webSSHWebSocketHandler: WebSSHWebSocketHandler
) : WebSocketConfigurer {
    override fun registerWebSocketHandlers(registry: WebSocketHandlerRegistry) {
        // 指定处理器和路径
        registry.addHandler(webSSHWebSocketHandler, "/webssh")
                .addInterceptors(ShellWebSocketInterceptor())
                .setAllowedOrigins("*")
    }
}